package com.gwnet.shop.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.log.annotation.Log;
import com.gwnet.common.log.enums.BusinessType;
import com.gwnet.common.mybatis.core.page.TableDataInfo;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.shop.domain.OrderInfo;
import com.gwnet.shop.domain.OrderPayment;
import com.gwnet.shop.service.IOrderPaymentService;
import com.gwnet.shop.utils.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单支付Controller
 * 
 * @author ruoyi
 * @date 2024-07-21
 */
@RestController
@RequestMapping("/orderpayment")
public class OrderPaymentController extends MBaseController
{
    @Resource
    private IOrderPaymentService orderPaymentService;

    /**
     * 查询订单支付列表
     */
    @SaCheckPermission("shop:orderpayment:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderPayment orderPayment)
    {
        startPage();
        List<OrderPayment> list = orderPaymentService.selectOrderPaymentList(orderPayment);
        return getDataTable(list);
    }

    /**
     * 获取订单支付详细信息
     */
    @SaCheckPermission("shop:orderpayment:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderPaymentService.selectOrderPaymentById(id));
    }

    /**
     * 新增订单支付
     */
//    @SaCheckPermission("shop:orderpayment:add")
//    @Log(title = "订单支付", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody OrderPayment orderPayment)
//    {
//        return toAjax(orderPaymentService.insertOrderPayment(orderPayment));
//    }

    /**
     * 新增订单支付
     */
    @Log(title = "订单支付完成稿的回调接口", businessType = BusinessType.INSERT)
    @PostMapping("/success")
    public AjaxResult success(@RequestBody OrderPayment orderPayment)
    {
        return toAjax(orderPaymentService.insertOrderPayment(orderPayment));
    }

    /**
     * 修改订单支付
     */
    @SaCheckPermission("shop:orderpayment:edit")
    @Log(title = "订单支付", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderPayment orderPayment)
    {
        orderPayment.setCreateBy( LoginHelper.getUserId() );
        return toAjax(orderPaymentService.updateOrderPayment(orderPayment));
    }



    /**
     * 删除订单支付
     */
    @SaCheckPermission("shop:orderpayment:remove")
    @Log(title = "订单支付", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderPaymentService.deleteOrderPaymentByIds(ids));
    }
}
